/*YuO8szH0cVixePu/Bt+mG1FEB4hauY/FkzN+awxCluloTZGsEXdz2qDszwqhhXkR*/
import { ajax } from 'nc-lightapp-front';
import { setBatchBtnsEnable } from './buttonClick';
import { handleCheck_range } from '../../card/events/buttonClick';
import { pageConfig } from '../const';
import ampub from 'ampub';
const { utils, components } = ampub;
const { listUtils } = utils;
const { setQueryInfoCache, setListValue, listConst } = listUtils;
const { LoginContext } = components;
const { loginContextKeys, getContext } = LoginContext;
const { searchAreaId, tableId, pagecode, url, bill_type } = pageConfig;

// 点击查询，获取查询区数据
export default function clickSearchBtn(props, searchVal, type, queryInfo, isRefresh) {
    if (!searchVal) {
        return;
    }

    // 获取交易类型编码
    const transi_type = getContext(loginContextKeys.transtype);
    if (!queryInfo) {
        queryInfo = props.search.getQueryInfo(searchAreaId);
    }
    // 分页信息
    const pageInfo = props.table.getTablePageInfo(tableId);
    queryInfo.pageInfo = pageInfo;
    queryInfo.pagecode = pagecode;
    queryInfo.billtype = bill_type;
    queryInfo.transtype = transi_type;

    // 缓存查询条件
    setQueryInfoCache.call(this, queryInfo, isRefresh, type);

    // 条件查询
    ajax({
        url: url.queryUrl,
        data: queryInfo,
        success: (res) => {
            if (res && res.data && res.data[tableId] && res.data[tableId].rows && res.data[tableId].rows.length > 0) {
                // 处理盘点范围多语
                res.data[tableId].rows.forEach((row) => {
                    handleCheck_range.call(this, row.values.check_range, true);
                });
            }
            setListValue.call(
                this,
                props,
                res,
                tableId,
                isRefresh ? listConst.SETVALUETYPE.refresh : listConst.SETVALUETYPE.query
            );
            setBatchBtnsEnable.call(this, props, tableId);
        }
    });
}

/*YuO8szH0cVixePu/Bt+mG1FEB4hauY/FkzN+awxCluloTZGsEXdz2qDszwqhhXkR*/